package com.weibo.service;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

import com.weibo.db.DataBaseConnection;
import com.weibo.entity.Separate;
import com.weibo.entity.Xiaobian;

public class XiaobianService extends  DataBaseConnection{

	public  void save(Xiaobian xb){
		String sql = "insert into xiaobian(xingming,huaming,shouji,youxiang,wangwang,weibo_id,weibo_name,des) " +
				"values('"+xb.getXingming()+"','"+xb.getHuaming()+"','"+xb.getShouji()+"','"+xb.getYouxiang()+"','"+xb.getWangwang()+"','"+xb.getWeibo_id()+"','"+xb.getWeibo_name()+"','"+xb.getDes()+"')" ;
		System.out.println("sql:" + sql);
		try {
			super.save(sql);
		} catch (SQLException e) {
			e.printStackTrace();
		}finally{
			super.closeAll();
		}
	}
	
	public List<Object> findAll(){
		String sql = "select * from xiaobian";
		ResultSet rs=null;
		try {
			rs = super.getResultSet(sql, null);
		} catch (SQLException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		List<Object> list = new ArrayList<Object>();
		try {
			while(rs.next()){
				Xiaobian xb = new Xiaobian();
					xb.setDes(rs.getString("des"));
					xb.setHuaming(rs.getString("huaming"));
					xb.setId(rs.getInt("id"));
					xb.setShouji(rs.getString("shouji"));
					xb.setWangwang(rs.getString("wangwang"));
					xb.setWeibo_id(rs.getInt("weibo_id"));
					xb.setWeibo_name(rs.getString("weibo_name"));
					xb.setXingming(rs.getString("xingming"));
					xb.setYouxiang(rs.getString("youxiang"));
					
				list.add(xb);
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return null;
		}finally{
			super.closeAll();
		}
		return list;
	
		
	}
	public static void main(String[] args) {
		

	}

}
